<template>
  <div class="account">
    <div class="shang">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>条件查询</span>
        </div>

        <el-form
          :inline="true"
          :model="formInline"
          size="mini"
          class="demo-form-inline"
        >
          <el-row>
            <el-col :span="6">
              <el-form-item label="订单编号">
                <el-input
                  v-model="formInline.orderSn"
                  placeholder="请输入订单编号"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="订单类型">
                <el-select
                  v-model="formInline.orderType"
                  placeholder="请选订单类型"
                >
                  <el-option label="正常订单" value="0" />
                  <el-option label="秒杀订单" value="1" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="支付方式">
                <el-select
                  v-model="formInline.payType"
                  placeholder="请选订单类型"
                >
                  <el-option label="未支付" value="0" />
                  <el-option label="支付宝" value="1" />
                  <el-option label="微信" value="2" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="订单状态">
                <el-select
                  v-model="formInline.status"
                  placeholder="请选订单类型"
                >
                  <el-option label="待付款" value="0" />
                  <el-option label="待发货" value="1" />
                  <el-option label="已发货" value="2" />
                  <el-option label="已完成" value="3" />
                  <el-option label="退货" value="4" />
                  <el-option label="无效订单" value="5" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="19">
              <el-form-item>
                <!-- <el-button type="primary" @click="chaxun">查询</el-button>
                <el-button @click="chonzhi">重置</el-button> -->
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item>
                <el-button type="primary" @click="chaxun">查询</el-button>
                <el-button @click="chonzhi">重置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>
    </div>
    <div class="xia">
      <el-table :data="list" highlight-current-row border style="width: 100%">
        <el-table-column type="index" label="#" width="50" />
        <el-table-column prop="orderSn" label="订单编号" width="180" />
        <el-table-column prop="payType" label="支付方式" width="180">
          <template v-slot="sisui">
            <el-tag
              v-if="sisui.row.payType === 0"
              color="#909399"
              style="color:#fff"
            >
              未支付
            </el-tag>
            <el-tag
              v-else-if="sisui.row.payType === 1"
              color="#409eff"
              style="color:#fff"
            >
              支付宝
            </el-tag>
            <el-tag
              v-else
              color="#67c13a"
              style="color:#fff"
            >
              微信
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="订单状态" width="180">
          <template v-slot="sisui">
            <el-tag v-if="sisui.row.status === 0" style="color:#fff" color="#e05151">
              待付款
            </el-tag>
            <el-tag v-else-if="sisui.row.status === 1" style="color:#fff" color="#d48721">
              待发货
            </el-tag>
            <el-tag v-else-if="sisui.row.status === 2" style="color:#fff" color="#801cc2">
              已发货
            </el-tag>
            <el-tag v-else-if="sisui.row.status === 3" style="color:#fff" color="#1c94c4">
              已完成
            </el-tag>
            <el-tag v-else-if="sisui.row.status === 4" style="color:#fff" color="#6b6a6a">
              退货
            </el-tag>
            <el-tag v-else style="color:#fff" color="#985cbb">
              无效订单
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="添加时间" width="180" />
        <el-table-column prop="memberUsername" label="用户账号" width="180" />
        <el-table-column prop="orderType" label="订单类型" width="180">
          <div class="zhengcahng">正常订单</div>
        </el-table-column>
        <el-table-column prop="confirmStatus" label="备注" width="180" />
        <el-table-column type="" fixed="right" label="操作" width="180">
          <template v-slot="sisui">
            <el-button type="primary" icon="el-icon-aim" @click="chakanxiangqing(sisui.row)">查看订单</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="start"
      :page-sizes="[1, 5, 10, 15]"
      :page-size="limit"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { findOrdersByPage } from '@/api/order/reference/index.js'
export default {
  data() {
    return {
      // 请求的数据
      list: [],
      start: 1,
      limit: 10,
      total: 0,
      formInline: {
        deliverySn: '',
        id: '',
        memberUsername: '',
        orderSn: '',
        orderType: '',
        payType: '',
        sourceType: '',
        status: ''
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      findOrdersByPage(this.start, this.limit, this.formInline).then((res) => {
        console.log(res)
        this.list = res.data.rows
        this.total = res.data.total
      })
    },
    // 点击条数/页触发请求新数据
    handleSizeChange(e) {
      this.limit = e
      this.init()
    },
    // 点击页数发送请求新数据
    handleCurrentChange(e) {
      this.start = e
      this.init()
    },
    // 点击重置按钮
    chonzhi() {
      this.formInline = {
        deliverySn: '',
        id: '',
        memberUsername: '',
        orderSn: '',
        orderType: '',
        payType: '',
        sourceType: '',
        status: ''
      }
      this.init()
    },
    // 点击查询
    chaxun() {
      this.init()
    },
    // 点击查看订单详情
    chakanxiangqing(e) {
      console.log(e)
      console.log(e.id)
      const id = e.id
      this.$router.push(`/order/OrderAmount?id=${id}`)
    }

  }
}
</script>

<style lang="scss" scoped>
.account {
  margin: 30px;
  .shang {
  }
  .xia {

    text-align: center;
    margin-top: 30px;
    .zhengcahng {
      width: 100px;
      height: 100%;
      color: #fa0000;
      background-color: #e2b6b6;
      text-align: center;
      border: 1px solid #41f31e;
    }
  }
}
</style>
